#include "headfiles.h"

using namespace std;

int main(int argc, char **argv) {
	if (argc != 2) {
		cout << "Usage: " << argv[0] << " filename" << endl;
		return 0;
	}

	char file_name[255];
	sprintf(file_name, "%s", argv[1]);

	NODE *root;
	NODE **node_list;
	int node_num;
	
	// create binary tree and get node list
	root = createBinaryTreeAll(file_name, node_list, node_num);

	// print the binary tree
	printBinaryTree(root);

	// Get the next node of each node
	cout << "Node num = " << node_num << endl;
	int i, j;
	for (i = 0; i < node_num; i++) {
		for (j = i; j < node_num; j++) {
			NODE *ancestor = findCommonAncestor(root, node_list[i], node_list[j]);
			cout << "The common ancestor of node: " << node_list[i]->i << " and node: ";
			cout << node_list[j]->i << " is: ";
			if (ancestor == NULL) {
				cout << "NULL!" << endl;
			}
			else {
				cout << ancestor->i << "." << endl;
			}
		}
	}

	destroyTree(root);

	return 0;
}

